package com.bustle.user.dto.user;

import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Stateless;

import com.bustle.commons.MapConverter;
import com.bustle.user.data.User;
import com.bustle.user.dto.address.DtoToAddressMapConverter;

@Local
public interface DtoToUserMapConverter extends MapConverter<UserDto, User>
{
  @Stateless
  public class DefaultDtoToUserMapConverter extends AbstractMapConverter<UserDto, User> implements DtoToUserMapConverter
  {
    @Override
    public void doMapping(UserDto aSource, User aDestination)
    {
      aDestination.setId(aSource.getId());
      aDestination.setFirstName(aSource.getFirstName());
      aDestination.setLastName(aSource.getLastName());
      aDestination.setBirthday(aSource.getBirthday());
      aDestination.setEmail(aSource.getEmail());
      aDestination.setType(aSource.getType());
      aDestination.setAddress(dtoToAddressConverter.map(aSource.getAddress(), aDestination.getAddress()));
    }

    @Override
    protected User build()
    {
      return new User();
    }

    @EJB
    protected DtoToAddressMapConverter dtoToAddressConverter;
  }
}